Skip to content

chore: pin agent-wallet withdrawal rounding and atomicity#1390

Merged
MicBun merged 4 commits into
mainfrom
chore/maa-withdraw-qa-hardening
Jun 5, 2026
Merged

chore: pin agent-wallet withdrawal rounding and atomicity#1390
MicBun merged 4 commits into
mainfrom
chore/maa-withdraw-qa-hardening

Conversation

@MicBun

@MicBun MicBun commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

resolves: https://github.com/truflation/website/issues/4038

Summary by CodeRabbit

  • Documentation

    • Updated fee calculation documentation to specify ROUND HALF-UP rounding for basis point fees, ensuring commission and payout amounts consistently reconcile to the gross amount.
  • Tests

    • Expanded withdrawal testing to cover commission rounding behavior, bridge-out atomicity scenarios, and multi-token ledger isolation.
  • Dependencies

    • Updated Kwil-DB dependency versions.

@MicBun MicBun requested a review from pr-time-tracker June 5, 2026 08:09
@MicBun MicBun self-assigned this Jun 5, 2026
@coderabbitai

coderabbitai Bot commented Jun 5, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@MicBun, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 31 minutes and 18 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b8a17346-ca01-474b-b8cc-dd883bec703f

📥 Commits

Reviewing files that changed from the base of the PR and between c9ccbac and 302b605.

📒 Files selected for processing (2)
  • tests/streams/maa/route_e2e_test.go
  • tests/streams/maa/withdraw_test.go
📝 Walkthrough

Walkthrough

This PR updates the kwil-db dependency versions, clarifies BPS fee rounding behavior in migration 049 to use ROUND HALF-UP instead of truncation, and extends the MAA withdrawal test suite with three new test cases covering commission rounding validation, bridge-out atomicity, and multi-token ledger isolation.

Changes

MAA Withdrawal BPS Rounding and Atomicity

Layer / File(s) Summary
Dependency update
go.mod
kwil-db and kwil-db/core pseudo-versions updated to newer builds.
BPS rounding specification
internal/migrations/049-maa-funding.sql
Migration 049 documentation revised to specify that bps fees compute using ROUND HALF-UP to whole base unit, replacing truncation description, and explaining how this avoids dust imbalance.
Withdrawal test suite expansion
tests/streams/maa/withdraw_test.go, tests/streams/maa/create_test.go
Package constants extended with TRUF bridge/escrow/ERC20 identifiers; callAsOn helper added to execute engine calls against specific DB handles for transaction rollback testing; imports updated; three new test functions added: testMAAWithdrawBpsRounding validates commission rounding across partial withdrawals, testMAABridgeOutExplicitRecipientAndAtomicity tests payout atomicity and explicit L1 recipient scenarios using manual transaction boundaries, testMAAWithdrawMultiTokenIsolation confirms USDC withdrawal does not affect TRUF balances; create_test.go argument formatting aligned for consistency.

Possibly related PRs

  • trufnetwork/node#1389: Both PRs modify MAA withdrawal/commission logic in migration 049 and extend tests/streams/maa/withdraw_test.go to validate commission behavior; this PR adds rounding documentation and tests that build on PR #1389's withdrawal feature.
  • trufnetwork/node#1291: Both PRs update kwil-db and kwil-db/core dependencies in go.mod in the context of withdrawal support and corresponding withdrawal test behavior.
  • trufnetwork/node#1337: Both PRs update the same go.mod dependencies (github.com/trufnetwork/kwil-db and github.com/trufnetwork/kwil-db/core) to newer pseudo-versions.

Suggested reviewers

  • pr-time-tracker

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 A rabbit hops through withdrawal streams,
Rounding half-up, living the dreams!
Commission and payout in perfect accord,
With ROUND HALF-UP, the ledger's restored.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'chore: pin agent-wallet withdrawal rounding and atomicity' directly matches the main changes: SQL migration documenting rounding behavior, test updates for withdrawal rounding and atomicity scenarios.
Docstring Coverage ✅ Passed Docstring coverage is 90.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/maa-withdraw-qa-hardening

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@holdex

holdex Bot commented Jun 5, 2026

Copy link
Copy Markdown

Time Submission Status

Member Status Time Action Last Update
MicBun ✅ Submitted 4h Update time Jun 5, 2026, 8:58 AM

You can submit time with the command. Example:

@holdex pr submit-time 15m

See available commands to help comply with our Guidelines.

@MicBun

MicBun commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

@holdex pr submit-time 4h

@MicBun

MicBun commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jun 5, 2026

Copy link
Copy Markdown
✅ Action performed

Full review finished.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/streams/maa/withdraw_test.go`:
- Around line 330-335: The test opens a transaction with platform.DB.BeginTx and
only calls spTx.Rollback explicitly at the end, risking leaked open transactions
on early returns; add a deferred rollback immediately after obtaining spTx
(e.g., defer func() { _ = spTx.Rollback(ctx) }()) so spTx is cleaned up on all
failure paths, keeping the existing explicit rollback/assertion at the end for
clarity; reference spTx and BeginTx to locate where to add the defer.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9f44dd78-8217-4f27-bd11-414e6f726596

📥 Commits

Reviewing files that changed from the base of the PR and between 61e945a and c9ccbac.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (4)
  • go.mod
  • internal/migrations/049-maa-funding.sql
  • tests/streams/maa/create_test.go
  • tests/streams/maa/withdraw_test.go

Comment thread tests/streams/maa/withdraw_test.go
@MicBun MicBun merged commit 6f94ff4 into main Jun 5, 2026
6 of 7 checks passed
@MicBun MicBun deleted the chore/maa-withdraw-qa-hardening branch June 5, 2026 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant